package com.fjrcloud.controller;

import com.fjrcloud.entity.BasePrice;
import com.fjrcloud.entity.LandStandard;
import com.fjrcloud.entity.PriceType;
import com.fjrcloud.service.BasePriceService;
import com.fjrcloud.service.LandStandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


/**
 * Created by shengjian.lin on 17-1-16.
 */
@Controller
@RequestMapping("land")
public class HtmlLandController {

    @Autowired
    private LandStandardService standardService;
    @Autowired
    private BasePriceService basePriceService;

    @RequestMapping("standard")
    public String standard(Model model, Integer id){

        BasePrice compensate = basePriceService.get(PriceType.compensate);
        if (compensate == null){
            compensate = new BasePrice();
            compensate.setType(PriceType.compensate);
            compensate.setPrice(0.0);
            compensate = basePriceService.save(compensate);
        }

        BasePrice impose = basePriceService.get(PriceType.impose);
        if (impose == null){
            impose = new BasePrice();
            impose.setType(PriceType.impose);
            impose.setPrice(0.0);
            impose = basePriceService.save(impose);
        }

        model.addAttribute("compensatePrice",compensate);
        model.addAttribute("imposePrice",impose);

        return "land-identified-standard";
    }

    @RequestMapping("editor")
    public String editor(Model model, Integer id){

        Page<LandStandard> building = standardService.listBuilding(null,null);
        Page<LandStandard> clearing = standardService.listClearing(null,null);

        model.addAttribute("buildingStandard",building.getContent());
        model.addAttribute("clearingStandard",clearing.getContent());

        return "land-detail";
    }
}
